﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;

namespace FilesPractice
{
    class Program
    {
        static void Main(string[] args)
        {
            //string newFolder = @"E:\Visual Studio\MyProjects_cbr\FilesPractice\New";
            //Directory.CreateDirectory(newFolder);

            //string[] files = Directory.GetFiles(@"E:\Visual Studio\MyProjects_cbr\FilesPractice\Resource", "*.txt",
            //    SearchOption.TopDirectoryOnly);

            //if (Directory.Exists(newFolder))
            //{
            //    foreach (var file in files)
            //    {
            //        //Console.WriteLine((file));
            //        string file2 = file.Replace("Resource", "New");
            //        File.Copy(file, file2);
            //        //File.Copy(file, @"E:\Visual Studio\MyProjects_cbr\FilesPractice\Resource\myfile.txt");
            //    }
            //}



            //bool isDirectiryExists = Directory.Exists(@"E:\Visual Studio\MyProjects_cbr\FilesPractice\Resource");

            //if (isDirectiryExists)
            //{
            //    Directory.Delete(@"E:\Visual Studio\MyProjects_cbr\FilesPractice\Resource", true);
            //}




            //foreach (var f in files)
            //{
            //    Console.WriteLine(f);
            //}
            //Console.ReadKey();

            //string text = "Вставка";

            //string newFolder = @"E:\Visual Studio\MyProjects_cbr\FilesPractice\New";
            //Directory.CreateDirectory(newFolder);


            //string[] files2 = Directory.GetFiles(newFolder, "*.txt",
            //    SearchOption.TopDirectoryOnly);

            //foreach (var file in files2)
            //{
            //    File.WriteAllText(file, text);
            //    File.AppendAllText(file, text);
            //}


            //string filePath = @"E:\Visual Studio\MyProjects_cbr\FilesPractice\New\myfile.txt";

            //Console.WriteLine("Расширение: {0}", Path.GetExtension(filePath));
            //Console.WriteLine("Filename: {0}", Path.GetFileName(filePath));
            //Console.WriteLine("Filename without extention: {0}", Path.GetFileNameWithoutExtension(filePath));
            //Console.WriteLine("Directory path to file: {0}", Path.GetDirectoryName(filePath));


            //FileInfo fileInfo = new FileInfo(path);
            //fileInfo.CopyTo(@"E:\Visual Studio\MyProjects_cbr\FilesPractice\New\myfile.txt");



            //Считать текст из файла HT.txt.
            //1) ќпределить количество слов в файле(вывести на консоль)
            //2) ќпределить самое длинное слово (вывести на консоль)
            string filePath = @"E:\Visual Studio\MyProjects_cbr\FilesPractice\New\HT.txt";

            string text = File.ReadAllText(filePath);
            text = text.Replace(Environment.NewLine, "");
            Console.WriteLine("All of text: {0}", text);
            Console.WriteLine();

            string[] words = text.Split(' ');
            int countWords = words.GetLength(0);
            Console.WriteLine("Words in text: {0}", countWords);
            Console.WriteLine();
            
            int compareStrings = 0;
            StringBuilder resultWord = new StringBuilder();

            foreach (var word in words)
            {
               if(word.Length > compareStrings)
                {
                    resultWord.Clear();
                    resultWord.Append(word);
                    compareStrings = word.Length;
                }
            }
            Console.WriteLine("Longest word: {0} of {1} symbols", resultWord, compareStrings);
        }
    }
}
